package com.xuan.webfinally.service.impl;

import com.xuan.webfinally.entity.LastestWeather;
import com.xuan.webfinally.entity.SlopeWeatherData;
import com.xuan.webfinally.mapper.SlopeWeatherDataMapper;
import com.xuan.webfinally.service.ISlopeWeatherDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuan.webfinally.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 气象监测数据表 服务实现类
 * </p>
 *
 * @author gyuxuan
 * @since 2025-05-18
 */
@Service
public class SlopeWeatherDataServiceImpl extends ServiceImpl<SlopeWeatherDataMapper, SlopeWeatherData> implements ISlopeWeatherDataService {


    @Autowired
    private SlopeWeatherDataMapper slopeWeatherDataMapper;
    /**
     * 获取天气信息
     *
     * @return
     */
    @Override
    public Result<Map<String, Object>> getLatestSlopeInfo() {
        LastestWeather lastestWeather = slopeWeatherDataMapper.getLatestSlopeInfo();


        Map<String, Object> result = new HashMap<>();

        result.put("type", "lr_two_col");
        result.put("title", "天气概况");


        List<Map<String, Object>> dataSet = new ArrayList<>();

        dataSet.add(Map.of(
                "icon", "/assets/comm/wdIcon.png",
                "label", "温度",
                "value", lastestWeather.getTemperature(),
                "unit", "℃"
        ));
        dataSet.add(Map.of(
                "icon", "/assets/comm/kqsdIcon.png",
                "label", "空气湿度",
                "value", lastestWeather.getHumidity(),
                "unit", "%"
        ));
        dataSet.add(Map.of(
                "icon", "/assets/comm/kqsdIcon.png",
                "label", "气压",
                "value", lastestWeather.getPressure(),
                "unit", "hpa"
        ));
        dataSet.add(Map.of(
                "icon", "/assets/comm/fsIcon.png",
                "label", "风速",
                "value", lastestWeather.getWindSpeed(),
                "unit", "km/h"
        ));

        result.put("dataSet", dataSet);


        return Result.success(result);
        //        icon: require('@/assets/comm/wdIcon.png'),
//        return Result.success(List.of(
//                Map.of( "label", "温度", "value", lastestWeather.getTemperature(), "unit", "℃"),
//                Map.of("label", "空气湿度", "value", lastestWeather.getHumidity(), "unit", "%"),
//                Map.of("label", "气压", "value", lastestWeather.getPressure(), "unit", "hPa"),
//                Map.of("label", "风速", "value", lastestWeather.getWindSpeed(), "unit", "km/h")
//        ));
    }
}
